{include file="public/header" /}
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">栏目管理</a>
                <a>
                    <cite>栏目列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <a href="/admin/sort/add.html" class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon"></i>增加</a>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th width="20">
                                    <input type="checkbox" name="" lay-skin="primary">
                                  </th>
                                  <th width="70">ID</th>
                                  <th>栏目名</th>
                                    <th>所属模型</th>
                                  <th width="50">排序</th>
                                  <th width="80">状态</th>
                                  <th width="250">操作</th>
                              </thead>
                              <tbody class="x-cate">
                                {volist name="list" id="v"}
                                    <tr cate-id='{$v['id']}' fid='0' >
                                        <td>
                                            <input type="checkbox" name="" lay-skin="primary">
                                        </td>
                                        <td>{$i}|{$v['id']}</td>
                                        <td>
                                            {:str_repeat("&nbsp;&nbsp;└",$v['level'])}{$v['catname']}
                                        </td>
                                <td>{:get_model_zd($v['model_id'])}</td>
                                        <td><input type="text" class="layui-input x-sort" name="order" value="{$v['disorder']}"></td>
                                        <td>
                                            <input type="checkbox" name="switch"  lay-text="开启|停用" {if condition="$v['status'] eq 1"}checked {/if} lay-skin="switch">
                                        </td>
                                        <td class="td-manage">
                                            <a href="/admin/sort/add/id/{$v.id}" class="layui-btn layui-btn layui-btn-xs"  ><i class="layui-icon">&#xe642;</i>编辑</a>
                                            <?php if($v['isopen']==1||session('admin_uid')==-1){?>
                                                <a href="/admin/sort/add/pid/{$v.id}" class="layui-btn layui-btn-warm layui-btn-xs"><i class="layui-icon">&#xe642;</i>添加子栏目</a>
                                                <a href="/admin/sort/del/id/{$v.id}" class="layui-btn-danger layui-btn layui-btn-xs" onclick='return confirm("您确定要删除吗？")' href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</a>
                                            <?php }?>
                                        </td>
                                    </tr>
                                {/volist}
                              </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>


            window.onload=function(){

                $(".layui-form-switch").click(function () {
                    id=$(this).parent().parent().attr("cate-id");
                    var jsonData = {
                        "id": id,
                    };
                    $.ajax({
                        type: "POST",
                        url: "/admin/sort/audit",
                        data: jsonData,
                        dataType: "json",
                        success: function(data){
                            if(data.status==0){
                                // alert(data.msg);
                            }else{
                                alert(data.msg);
                                return false;
                            }
                        },
                        error:function(data) {
                            alert(data.msg);
                        }
                    });
                })


            }



            layui.use(['form'], function(){
            form = layui.form;
            
          });

           /*用户-删除*/
          function member_del(obj,id){
              layer.confirm('确认要删除吗？',function(index){
                  //发异步删除数据
                  $(obj).parents("tr").remove();
                  layer.msg('已删除!',{icon:1,time:1000});
              });
          }

          // 分类展开收起的分类的逻辑
          // 
          $(function(){
            $("tbody.x-cate tr[fid!='0']").hide();
            // 栏目多级显示效果
            $('.x-show').click(function () {
                if($(this).attr('status')=='true'){
                    $(this).html('&#xe625;'); 
                    $(this).attr('status','false');
                    cateId = $(this).parents('tr').attr('cate-id');
                    $("tbody tr[fid="+cateId+"]").show();
               }else{
                    cateIds = [];
                    $(this).html('&#xe623;');
                    $(this).attr('status','true');
                    cateId = $(this).parents('tr').attr('cate-id');
                    getCateId(cateId);
                    for (var i in cateIds) {
                        $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                    }
               }
            })
          })

          var cateIds = [];
          function getCateId(cateId) {
              $("tbody tr[fid="+cateId+"]").each(function(index, el) {
                  id = $(el).attr('cate-id');
                  cateIds.push(id);
                  getCateId(id);
              });
          }
   
        </script>
    </body>
</html>
